package Review;

import java.util.Stack;

public class Test22 {

	public static void main(String[] args) {
		int[] pushArray={1,2,3,4,5};
		int[] popArray={4,3,5,2,1};
		System.out.println(isPopOrder(pushArray,popArray));
	}
	public static boolean isPopOrder(int[] pushArray,int[]popArray){
	   if (pushArray==null||popArray==null||pushArray.length == 0 || popArray.length == 0){
	        return false;
	   }
	   Stack<Integer> stack = new Stack<Integer>();
	   int j=0;
	   for(int i=0;i<pushArray.length;i++){
		   stack.push(pushArray[i]);
		   while(j<popArray.length&&stack.peek()==popArray[j]){
			   stack.pop();
			   j++;
		   }
	   }
	   return stack.isEmpty();
	}

}
